//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.hl.sfzy.controller;

import com.hl.sfzy.entity.Problem;
import com.hl.sfzy.service.ProblemService;
import com.hl.sfzy.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping({"/problem"})
public class ProblemController {
    @Autowired
    private ProblemService ProblemService;

    public ProblemController() {
    }

    @PostMapping({"/add"})
    public Result add(@RequestBody Problem Problem) throws Exception {
        this.ProblemService.add(Problem);
        return Result.success();
    }

    @PutMapping({"/edit"})
    public Result edit(@RequestBody Problem Problem) {
        this.ProblemService.edit(Problem);
        return Result.success();
    }

    @DeleteMapping({"/remove/{id}"})
    public Result remove(@PathVariable Integer id) {
        this.ProblemService.remove(id);
        return Result.success();
    }

    @DeleteMapping({"/remove"})
    public Result removeBatch(Integer[] ids) {
        System.out.println(ids);
        this.ProblemService.removeBatch(ids);
        return Result.success();
    }

    @GetMapping({"/find/{id}"})
    public Result findById(@PathVariable Integer id) {
        return Result.success(this.ProblemService.findById(id));
    }

    @GetMapping({"/find"})
    public Result findPage(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize, Problem problem) {
        System.out.println(problem);
        return Result.success(this.ProblemService.findPage(pageNum, pageSize, problem));
    }

    @GetMapping({"/findbyUserid/{id}"})
    public Result findByuserid(@PathVariable Integer id) {
        return Result.success(this.ProblemService.findByuserid(id));
    }
    @GetMapping({"/findbyplo"})
    public Result findByPlo(@RequestParam(value = "pageNum",required = false,defaultValue = "1") Integer pageNum, @RequestParam(value = "pageSize",required = false,defaultValue = "10") Integer pageSize, Problem problem) {
        return Result.success(this.ProblemService.findByPlo(pageNum, pageSize, problem));
    }
}
